package com.gk.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.pojo.TbMemberLevel;
import com.eight.vo.ComResult;
import com.eight.vo.TbMemberLevelVo;
import com.gk.dao.TbMemberLevelDao;
import com.gk.service.TbMemberLevelService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: GK
 * @date: 2023/2/28 10:41
 * @version:No1.0
 */
@Service(value = "tbMemberLevelService")
public class TbMemberLevelServiceImpl  extends ServiceImpl<TbMemberLevelDao, TbMemberLevel> implements TbMemberLevelService {

    @Resource
    private TbMemberLevelDao tbMemberLevelDao;

    /**
     * 分页查询数据
     * @param tbMemberLevelVo 查询条件
     * @param pageIndex 当前页
     * @param pageSize 页中数据数量
     * @return
     */
    @Override
    public Page<TbMemberLevel> selectAll(TbMemberLevelVo tbMemberLevelVo, Integer pageIndex, Integer pageSize) {
        Page<TbMemberLevel> page = new Page<>(pageIndex,pageSize);
        page=tbMemberLevelDao.selectAll(page,tbMemberLevelVo);
      return page;
    }

    /**
     * 查询所有的等级
     * @return
     */
    @Override
    public ComResult selectName() {
        List<TbMemberLevel> tbMemberLevels = tbMemberLevelDao.selectName();
        if(tbMemberLevels!=null){
            return new ComResult(2000,"查询成功",tbMemberLevels);
        }else{
            return new ComResult(5000,"查询失败");
        }
    }

    /**
     * 根据ID进行删除条件
     * @param id 删除条件
     * @return 响应前端
     */
    @Override
    public ComResult deleteFindId(Integer id) {
        int i = tbMemberLevelDao.deleteById(id);
        if(i>0){
            return new ComResult(2000,"删除成功");
        }else{
            return new ComResult(5000,"删除失败");
        }
    }

    /**
     * 添加会员等级信息
     * @param tbMemberLevel 添加的会员等级信息
     * @return 响应前端
     */
    @Override
    public ComResult insertMemberLevel(@Param("tbMemberLevel") TbMemberLevel tbMemberLevel) {
        int insert = tbMemberLevelDao.insert(tbMemberLevel);
        if(insert>0){
            return new ComResult(2000,"添加成功");
        }else{
            return  new ComResult(5000,"添加失败");
        }
    }

    /**
     * 修改会员等级信息
     * @param tbMemberLevel 修改的信息
     * @return 响应前端
     */
    @Override
    public ComResult updateMemberLevel(TbMemberLevel tbMemberLevel) {
        int i = tbMemberLevelDao.updateById(tbMemberLevel);
        if(i>0){
            return new ComResult(2000,"修改成功");
        }else{
            return new ComResult(5000,"修改失败");
        }
    }
}
